<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
class DealController extends CommonController{
    public function deal_list(){
        return view('admin.deal.deal_list');
    }
    public function deal_order(){
        return view('admin.deal.deal_order');
    }
    public function deal_order_manage($key="",$info=""){
        if(!empty($key) && !empty($info)){
            $data = DB::table('mo_indent_goods')
                ->join('mo_indent', 'mo_indent_goods.i_id', '=', 'mo_indent.i_id')
                ->where('mo_indent_goods.i_number','=',$key)
                ->where('mo_indent.i_time','=',$info)
                ->select('mo_indent_goods.*', 'mo_indent.*')
                ->paginate(1) ;
        }elseif(!empty($key) && empty($info)){
            $data = DB::table('mo_indent_goods')
                ->join('mo_indent', 'mo_indent_goods.i_id', '=', 'mo_indent.i_id')
                ->where('mo_indent_goods.i_number','=',$key)
                ->orwhere('mo_indent.i_time','=',$key)
                ->select('mo_indent_goods.*', 'mo_indent.*')
                ->paginate(1) ;
        }else{
            $data = DB::table('mo_indent_goods')
                ->join('mo_indent', 'mo_indent_goods.i_id', '=', 'mo_indent.i_id')
                ->select('mo_indent_goods.*', 'mo_indent.*')
                ->paginate(2) ;
        }
        return view('admin.deal.deal_order_manage',compact('data'));
    }
    //单删
    public function del($id){
        if(session('r_id') != 1) {
            $res = $this->ifright();
            if ($res == "no" || $res == NULL) {
                $title = array('content' => '你暂时没有此权限', 'url' => 'deal_order_manage');
                return view('admin.alert', ['data' => $title]);
            } else {
                DB::table('mo_indent_goods')->where(["i_id" => $id])->delete();
                DB::table('mo_indent')->where(["i_id" => $id])->delete();
                return Redirect('deal/deal_order_manage');
            }
        }else{
            DB::table('mo_indent_goods')->where(["i_id" => $id])->delete();
            DB::table('mo_indent')->where(["i_id" => $id])->delete();
            return Redirect('deal/deal_order_manage');
        }
    }
    //多删
    public function dels($str){
        $str = explode(",",$str);
        if(session('r_id') != 1) {
            $res = $this->ifright();
            if ($res == "no" || $res == NULL) {
                $title = array('content' => '你暂时没有此权限', 'url' => 'deal_order_manage');
                return view('admin.alert', ['data' => $title]);
            } else {
                foreach ($str as $v) {
                    DB::table('mo_indent_goods')->where(["i_id" => $v])->delete();
                    DB::table('mo_indent')->where(["i_id" => $v])->delete();
                }
                return Redirect('deal/deal_order_manage');
            }
        }else{
            foreach ($str as $v) {
                DB::table('mo_indent_goods')->where(["i_id" => $v])->delete();
                DB::table('mo_indent')->where(["i_id" => $v])->delete();
            }
            return Redirect('deal/deal_order_manage');
        }
    }
    public static function search(){
        $key = trim($_GET['keys']);
        $info = trim($_GET['dinfo']);
        $data = DB::table('mo_indent_goods')
            ->join('mo_indent', 'mo_indent_goods.i_id', '=', 'mo_indent.i_id')
            ->where('mo_indent_goods.i_number','=',$key)
            ->where('mo_indent.i_time','=',$info)
            ->select('mo_indent_goods.*', 'mo_indent.*')
            ->paginate(1) ;
        return view('admin.deal.deal_order_manage',compact('data'));
    }
}
?>


